Skip to content

Conversation

SergeiPavlov
Copy link
Collaborator

@SergeiPavlov SergeiPavlov commented Nov 4, 2023

Assembly code generated by JIT for Entity.Field getter:

before optimization (without .tail):

push        rbp  
sub         rsp,20h  
lea         rbp,[rsp+20h]  
mov         qword ptr [rbp+10h],rcx  
mov         r8,1914C813828h  
mov         r8,qword ptr [r8]  
mov         rcx,qword ptr [rbp+10h]  
mov         rdx,7FFA24FE6D40h  
call        qword ptr [CLRStub[MethodDescPrestub]@00007FFA24FCB078 (07FFA24FCB078h)]  ; GetFieldValue<>()
nop  
add         rsp,20h  
pop         rbp  
ret 

After optimization (with .tail):

mov         r8,1F7CFC13828h  
mov         r8,qword ptr [r8]  
mov         rdx,7FFA24FE20B0h  
jmp         qword ptr [CLRStub[MethodDescPrestub]@00007FFA25001FA8 (07FFA25001FA8h)]   ; GetFieldValue<>()

The same effect for setters (SetFieldValue())

The assembly was build with enabled optimization.

The JIT itself does not apply this kind of optimization
see https://stackoverflow.com/questions/491376/why-doesnt-net-c-optimize-for-tail-call-recursion
dotnet/csharplang#2304

@SergeiPavlov SergeiPavlov merged commit ae46f6e into master-servicetitan Nov 7, 2023
@SergeiPavlov SergeiPavlov deleted the weaverTail branch November 7, 2023 00:44
SergeiPavlov added a commit that referenced this pull request Dec 28, 2023
* Tail prefix in weaver

* Revert version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants